define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'fbdomestic/index' + location.search,
                    add_url: 'fbdomestic/add',
                    edit_url: 'fbdomestic/edit',
                    del_url: 'fbdomestic/del',
                    multi_url: 'fbdomestic/multi',
                    import_url: 'fbdomestic/import',
                    table: 'fbdomestic',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                searchFormVisible: true,
                columns: [
                    [
                        {checkbox: true},
                        //{field: 'id', title: __('Id')},
                        {field: 'attribution', title: __('Attribution'),visible: false,addClass: "selectpage", extend: "data-source='auth/admin/index' data-field='nickname'"},
                        {field: 'admin_name', title: __('Attribution'), operate: false},
                        {field: 'company', title: __('Company'), operate: 'LIKE'},
                        {field: 'social_credit_code', title: __('Social_credit_code'), operate: 'LIKE'},
                        //{field: 'advertising_account', title: __('Advertising_account'), operate: false},
                        //{field: 'fb_page', title: __('Fb_page'), operate: false},
                        {field: 'binding_bm', title: __('Binding_bm'), operate: 'LIKE'},
                        {field: 'domain', title: __('Domain'), operate: 'LIKE'},
                        {field: 'business_premises', title: __('Business_premises'), operate: 'LIKE'},
                        {field: 'zip_code', title: __('Zip_code'), operate: 'LIKE'},
                        {field: 'email', title: __('Email'), operate: 'LIKE'},
                        //{field: 'pic', title: __('Pic'), operate: false, events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'pics', title: __('营业执照下载链接'), operate: false, formatter: Table.api.formatter.url},
                        {field: 'phone', title: __('Phone'), operate: 'LIKE'},
                        {field: 'account_note', title: __('Account_note'), operate: 'LIKE'},
                        {field: 'createtime', title: __('Createtime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"MM-DD HH:mm"},
                        {field: 'updatetime', title: __('Updatetime'), operate:'RANGE', addclass:'datetimerange', autocomplete:false, formatter: Table.api.formatter.datetime, datetimeFormat:"MM-DD HH:mm"},
                        {field: 'status', title: __('Status'), searchList: {"apply":__('申请中'),"normal":__('已通过'),"pay":__('已充值'),"hidden":__('申请驳回')}, formatter: Table.api.formatter.status,custom: {hidden:'danger', normal:'success', apply:'warning', pay:'warning'}},
                        {field: 'user_status', title: __('使用状态'), searchList: {"normal":__('使用中'),"hidden":__('待分配')}, formatter: Table.api.formatter.status},
                        {field: 'operate', title: __('Operate'), table: table, events: Table.api.events.operate, formatter: Table.api.formatter.operate}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            var cpic = $('#c-pic').val();
            if(cpic !== ''){
                cpic = 'http://121.5.76.151:100' + cpic;
            }
            $('#c-pictext').val(cpic);
            $('#c-pic').bind('input propertychange', function() {
                var cpic = $('#c-pic').val();
                if(cpic !== ''){
                    cpic = 'http://121.5.76.151:100' + cpic;
                }
                $('#c-pictext').val(cpic);
            });
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});